package jnpf.engine.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.service.SuperServiceImpl;
import jnpf.engine.entity.FlowTaskMessageEntity;
import jnpf.engine.mapper.FlowTaskMessageMapper;
import jnpf.engine.model.flowbefore.FlowBeforeListVO;
import jnpf.engine.service.FlowTaskMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class FlowTaskMessageServiceImpl extends SuperServiceImpl<FlowTaskMessageMapper, FlowTaskMessageEntity> implements FlowTaskMessageService {

    @Override
    public void saveList(FlowBeforeListVO  listVO) {
        QueryWrapper<FlowTaskMessageEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(FlowTaskMessageEntity::getTaskNodeId, listVO.getThisStepId());
        queryWrapper.lambda().eq(FlowTaskMessageEntity::getTaskId, listVO.getProcessId());
        queryWrapper.lambda().eq(FlowTaskMessageEntity::getAssigneMObile, listVO.getAssigneMObile());
        FlowTaskMessageEntity flowTaskMessageEntity = this.baseMapper.selectOne(queryWrapper);
        if(flowTaskMessageEntity==null){
            FlowTaskMessageEntity flowTaskMessageEntity1 =new FlowTaskMessageEntity();
            flowTaskMessageEntity1.setTaskId(listVO.getProcessId());
            flowTaskMessageEntity1.setTaskNodeId(listVO.getThisStepId());
            flowTaskMessageEntity1.setAssigneMObile(listVO.getAssigneMObile());
            flowTaskMessageEntity1.setDatInfo(JSONUtil.toJsonStr(listVO));
            this.save(flowTaskMessageEntity1);
        }


    }
}
